<template>
  <div>
    <avue-crud class='flowTable' :option="option" :table-loading="loading" :data="data" ref="crud" v-model="form" @row-del="rowDel" @row-update="rowUpdate" @row-save="rowSave" :before-open="beforeOpen" @selection-change="selectionChange" @refresh-change="refreshChange" @on-load="onLoad">
      <template slot="menuRight">
        <table-right :crud='$refs.crud' :data='data' :searchBtn='false' :columnBtn='true' :addPermission="addBtn&&this.productId&&!created" :handleAdd='handleAdd' :handleDelete="handleDelete" :delPermission="false" :refreshChange='refreshChange'>
          <el-tooltip class="item" effect="dark" content="编辑" placement="bottom">
            <el-button icon="el-icon-edit" size="small" type="text" @click.stop="updateBatchFun" v-if="editBtn&&created">批量编辑</el-button>
          </el-tooltip>
        </table-right>
      </template>
      <template slot="procedureIdForm" slot-scope="{disabled}">
        <el-select v-model="form.procedureId" placeholder="请选择" :disabled='disabled'>
          <el-option v-for="item in procedureList" :key="item.id" :label="item.procedureName" :value="item.id">
            <span style="float: left">{{ item.procedureName }}</span>
            <span style="float: right; color: #8492a6; font-size: 13px">{{ item.produceLineName }}</span>
          </el-option>
        </el-select>
      </template>
      <template slot-scope="{row}" slot="procedureId">
        {{row.procedureName}}
      </template>
      <template slot-scope="{row}" slot="reportArtifacts">
        {{row.reportArtifactsName}}
      </template>
      <template slot-scope="{row}" slot="processIcon">
        <i class="iconfont icon-zhengfangxing1" v-if='row.iconType=="1"'></i>
        <i class="iconfont icon-yuanxing" v-if='row.iconType=="2"'></i>
        <i class="iconfont icon-sanjiaoxing" v-if='row.iconType=="3"'></i>
        <i class="iconfont icon-zhengfangxing" v-if='row.iconType=="4"'></i>
      </template>
      <template slot-scope="{row}" slot="moveIcon">
      </template>
      <template slot-scope="{row}" slot="saveIcon">
      </template>
      <template slot-scope="{row}" slot="checkIcon">
      </template>
      <template slot-scope="{row}" slot="boxCounts">
        <span>{{row.boxCounts}} 件</span>
      </template>
      <template slot-scope="{row}" slot="boxCountsForm">
        <span v-if="type=='view'" style="padding:15px;font-size:12px">{{row.boxCounts}} 件</span>
      </template>
      <template slot-scope="{row}" slot="productFeature">
        <ol v-if="row.productScNames.length>0" style="margin-block-start:0;margin-block-end:0;padding-inline-start:8px">
          <li v-for="(item,index) in row.productScNames" :key="index">{{item}}</li>
        </ol>
      </template>
      <template slot-scope="{row}" slot="procedureFeature">
        <ol v-if="row.procedureScNames.length>0" style="margin-block-start:0;margin-block-end:0;padding-inline-start:8px">
          <li v-for="(item,index) in row.procedureScNames" :key="index">{{item}}</li>
        </ol>
      </template>
      <template slot="infoForm" slot-scope="scope">
        <avue-crud :table-loading="infoloading" :option="infoOption" :data="infoData" v-model="infoForm">
          <template slot-scope="{ row }" slot="procedureId">
            {{ row.procedureName }}
          </template>
          <template slot-scope="{row}" slot="reportArtifactsType">
            <el-select v-model="row.reportArtifactsType" placeholder="请选择报工件类别" @change="(value)=>{changeReportType(value,row,row.$index)}">
              <el-option v-for="item in reportTypeList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey">
              </el-option>
            </el-select>
          </template>
          <template slot-scope="{row}" slot="reportArtifacts">
            <el-select size="mini" v-model="row.reportArtifacts" filterable placeholder="请选择工序产品" @change="(value)=>{changeReportPro(value,row,row.$index)}">
              <el-option v-for="item in row.reportArtifactList" :key="item.label" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </template>
        </avue-crud>
      </template>
      <template slot="characterForm" slot-scope="scope">
        <avue-crud :table-loading="characterloading" :option="characterOption" :data="characterData" v-model="characterForm" @row-del="rowCharDel" @row-update="rowCharUpdate" @row-save="rowCharSave">
          <template slot-scope="{row}" slot="productSc">
            <el-select v-model="row.productSc" placeholder="请选择" filterable @change="(value)=>{changeProductSc(value,row,row.$index)}">
              <el-option v-for="item in productScList" :key="item.id" :label="item.productSc" :value="item.id">
              </el-option>
            </el-select>
          </template>
        </avue-crud>
      </template>
      <template slot-scope="{row}" slot="menu">
        <el-tooltip class="item" effect="dark" content="查看" placement="bottom">
          <el-button icon="el-icon-view" size="small" type="text" @click.stop="$refs.crud.rowView(row,row.$index)" v-if="viewBtn"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="编辑" placement="bottom">
          <el-button icon="el-icon-edit" size="small" type="text" @click.stop="$refs.crud.rowEdit(row,row.$index)" v-if="editBtn"></el-button>
        </el-tooltip>
        <!-- <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
          <el-button icon="el-icon-delete" size="small" type="text" @click.stop="rowDel(row)" v-if="permission.public_flow_delete"></el-button>
        </el-tooltip> -->
      </template>
    </avue-crud>

  </div>
</template>
<script>
import {
  getFlowList,
  addFlow,
  uploadBatchFlow,
  removeFlow,
  updateFlow,
  getFlow,
  getProdProcess,
  getTypeProducts,
  getProProcessList,
  getProdFeatures,
} from '@/api/project/productData/processData';
import { getQualityList } from '@/api/project/information/base';
import { getTemplate } from '@/api/projectplan/template';
import { getBusinessList } from '@/api/zidian';
import { mapGetters } from 'vuex';
import { numparZReg, numParseReg } from '@/util/zhengze';
import { init } from '@/mixins/init';

export default {
  mixins: [init],
  props: {
    productId: {
      type: String,
    },
    addBtn: {
      type: Boolean,
    },
    viewBtn: {
      type: Boolean,
    },
    editBtn: {
      type: Boolean,
    },
    delBtn: {
      type: Boolean,
    },
    materialName: {
      type: String,
    },
    innerDrawingNo: {
      type: String,
    },
    materialNo: {
      type: String,
    },
    type: {
      type: String,
    },
  },
  data() {
    return {
      fileTitle: '过程流程图',
      procedureList: [],
      typeProducts: [],
      infoloading: false,
      created: false,
      option: {
        dialogHeight: '100%',
        dialogWidth: '80%',
        page: false,
        tip: false,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        viewBtn: false,
        delBtn: false,
        editBtn: false,
        addBtn: false,
        menuWidth: 100,
        columnBtn: true,
        filterBtn: true,
        dialogClickModal: false,
        labelWidth: 120,
        addTitle: '新增',
        column: [
          {
            label: '产品名称',
            prop: 'materialName',
            disabled: true,
            editDisplay: false,
            viewDisplay: false,
            span: 8,
            hide: true,
            showColumn: false,
          },
          {
            label: '产品图号',
            prop: 'innerDrawingNo',
            disabled: true,
            editDisplay: false,
            viewDisplay: false,
            span: 8,
            hide: true,
            showColumn: false,
          },
          {
            label: '产品编码',
            prop: 'materialNo',
            disabled: true,
            editDisplay: false,
            viewDisplay: false,
            span: 8,
            hide: true,
            showColumn: false,
          },
          {
            label: '文件编号',
            prop: 'fileNo',
            editDisplay: false,
            viewDisplay: false,
            disabled: false,
            span: 8,
            maxlength: 18,
            hide: true,
            showColumn: false,
            rules: [
              {
                required: true,
                message: '请输入文件编号',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '版本',
            prop: 'version',
            editDisplay: false,
            viewDisplay: false,
            disabled: false,
            span: 8,
            maxlength: 5,
            hide: true,
            showColumn: false,
            rules: [
              {
                required: true,
                message: '请输入版本',
                trigger: 'blur',
              },
            ],
          },
          {
            labelWidth: 0,
            label: '',
            prop: 'info',
            span: 24,
            hide: true,
            formslot: true,
            addDisplay: true,
            editDisplay: false,
            viewDisplay: false,
          },
          {
            label: '步骤序号',
            prop: 'stepNo',
            addDisplay: false,
            disabled: true,
            span: 12,
            minWidth: 70,
            maxlength: 5,
            // rules: [
            //   {
            //     required: true,
            //     message: '请输入步骤序号',
            //     trigger: 'blur',
            //   },
            //   {
            //     pattern: numparZReg,
            //     message: '只能为正整数（包含0）',
            //     trigger: 'blur',
            //   },
            // ],
          },
          {
            label: '步骤类型',
            prop: 'iconType',
            addDisplay: false,
            span: 12,
            hide: true,
            showColumn: false,
            type: 'select',
            dicUrl: '/api/blade-system/dict-biz/dictionary?code=processType',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            rules: [
              {
                required: true,
                message: '请选择步骤类型',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '过程',
            prop: 'processIcon',
            minWidth: 70,
            display: false,
            align: 'center',
            slot: true,
          },
          {
            label: '工序名称',
            prop: 'procedureId',
            addDisplay: false,
            disabled: true,
            type: 'select',
            formslot: true,
            slot: true,
            minWidth: 120,
            dicData: [],
            props: {
              label: 'name',
              value: 'id',
            },
            span: 12,
            // maxlength: 30,
            rules: [
              {
                required: true,
                message: '请选择工序名称',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '产品特性',
            prop: 'productFeature',
            span: 24,
            slot: true,
            display: false,
            minWidth: 150,
            maxlength: 30,
            overHidden: true,
          },
          {
            label: '过程特性',
            prop: 'procedureFeature',
            span: 24,
            slot: true,
            display: false,
            minWidth: 150,
            maxlength: 30,
            overHidden: true,
          },
          {
            label: '报工方式',
            prop: 'reportType',
            addDisplay: false,
            span: 12,
            hide: true,
            showColumn: false,
            type: 'select',
            dicUrl: '/api/blade-system/dict-biz/dictionary?code=reportType',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            // value: '1',
            rules: [
              {
                required: true,
                message: '请选择报工方式',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '报工件类别',
            prop: 'reportArtifactsType',
            addDisplay: false,
            span: 12,
            hide: true,
            showColumn: false,
            type: 'select',
            dicUrl: '/api/blade-system/dict-biz/dictionary?code=reportArtifactsType',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            // value: 'PB',
            rules: [
              {
                required: true,
                message: '请选择报工件类别',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '工序产品',
            prop: 'reportArtifacts',
            addDisplay: false,
            slot: true,
            span: 12,
            minWidth: 100,
            maxlength: 30,
            overHidden: true,
            type: 'select',
            filterable: true,
            dicData: [],
            rules: [
              {
                required: true,
                message: '请选择工序产品',
                trigger: 'blur',
              },
            ],
          },

          {
            label: '标箱数量(件)',
            prop: 'boxCounts',
            addDisplay: false,
            slot: true,
            span: 12,
            minWidth: 130,
            maxlength: 5,
            type: 'number',
            minRows: 1,
            maxRows: 99999,
            precision: 0,
            overHidden: true,
            append: '件',
            rules: [
              {
                required: true,
                message: '请输入标箱数量',
                trigger: 'blur',
              },
              {
                pattern: numparZReg,
                message: '只能为整数（包含0）',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '定额',
            prop: 'quota',
            addDisplay: false,
            span: 12,
            minWidth: 130,
            maxlength: 6,
            type: 'number',
            minRows: 1,
            maxRows: 999999,
            precision: 0,
            overHidden: true,
            rules: [
              {
                required: true,
                message: '请输入定额',
                trigger: 'blur',
              },
              {
                pattern: numParseReg,
                message: '只能为正整数（不包含0）',
                trigger: 'blur',
              },
            ],
          },
          {
            labelWidth: 0,
            label: '',
            prop: 'character',
            span: 24,
            hide: true,
            formslot: true,
            addDisplay: false,
          },
        ],
      },
      type: '',
      data: [],
      infoOption: {
        page: false,
        // menuWidth: 130,
        menu: false,
        header: false,
        // cellBtn: true,
        editBtn: false,
        column: [
          {
            label: '工序号',
            prop: 'combinationProcedureNo',
            width: 80,
          },
          {
            label: '工序',
            prop: 'procedureName',
          },
          {
            label: '步骤类型',
            prop: 'iconType',
            addDisplay: false,
            cell: true,
            span: 12,
            type: 'select',
            dicUrl: '/api/blade-system/dict-biz/dictionary?code=processType',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            rules: [
              {
                required: true,
                message: '请选择步骤类型',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '报工方式',
            prop: 'reportType',
            addDisplay: false,
            cell: true,
            span: 12,
            type: 'select',
            dicUrl: '/api/blade-system/dict-biz/dictionary?code=reportType',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            // value: '1',
            // rules: [
            //   {
            //     required: true,
            //     message: '请选择报工方式',
            //     trigger: 'blur',
            //   },
            // ],
          },
          {
            label: '报工件类别',
            prop: 'reportArtifactsType',
            addDisplay: false,
            hide: false,
            span: 12,
            minWidth: 130,
            cell: true,
            // type: 'select',
            // dicUrl: '/api/blade-system/dict-biz/dictionary?code=reportArtifactsType',
            // props: {
            //   label: 'dictValue',
            //   value: 'dictKey',
            // },
            // value: 'PB',
            slot: true,
          },
          {
            label: '工序产品',
            prop: 'reportArtifacts',
            addDisplay: false,
            hide: false,
            cell: true,
            slot: true,
            span: 24,
            minWidth: 130,
            maxlength: 30,
            overHidden: true,
          },

          {
            label: '标箱数量(件)',
            prop: 'boxCounts',
            cell: true,
            span: 12,
            minWidth: 130,
            maxlength: 5,
            type: 'number',
            minRows: 1,
            maxRows: 99999,
            precision: 0,
            overHidden: true,
          },
          {
            label: '定额',
            prop: 'quota',
            addDisplay: false,
            cell: true,
            span: 12,
            minWidth: 130,
            maxlength: 6,
            type: 'number',
            minRows: 1,
            maxRows: 999999,
            precision: 0,
            overHidden: true,
          },
        ],
      },
      infoData: [],
      infoForm: {},
      reportTypeList: [],
      reportArtifacts: [],
      characterloading: false,
      characterOption: {
        page: false,
        menuWidth: 80,
        addRowBtn: true,
        header: true,
        menu: true,
        // cellBtn: true,
        delBtn: true,
        editBtn: false,
        addBtn: false,
        column: [
          {
            label: '产品特性',
            prop: 'productSc',
            span: 12,
            cell: true,
            slot: true,
            minWidth: 150,
            overHidden: true,
            maxlength: 30,
            rules: [
              {
                required: true,
                message: '请输入产品特性',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '过程特性',
            prop: 'procedureSc',
            span: 12,
            minWidth: 150,
            overHidden: true,
            maxlength: 30,
          },
          {
            label: '特性分类',
            prop: 'scKind',
            minWidth: 60,
            span: 12,
            type: 'select',
            dicData: [],
            // dicUrl: '/api/blade-system/dict-biz/dictionary?code=featureType',
            props: {
              label: 'quaType',
              value: 'id',
            },
            rules: [
              {
                required: true,
                message: '请选择特性分类',
                trigger: 'blur',
              },
            ],
          },
        ],
      },
      characterData: [],
      characterForm: {},
      productScList: [],
      reportArtifactList: [],
      updateBatch: false,
    };
  },
  computed: {
    ...mapGetters(['userInfo', 'permission']),
  },
  created() {
    this.onLoad();
  },
  watch: {
    productId(newVal, oldVal) {
      if (newVal) {
        this.onLoad();
      }
    },
    'form.reportArtifactsType'(val, oldVal) {
      if (val) {
        this.$set(this.form, 'reportArtifacts', '');
        const column = this.findObject(this.option.column, 'reportArtifacts');
        getTypeProducts({ materialType: val }).then((res) => {
          const data = res.data.data;
          if (data.length == 0) {
            column.dicData.length = 0;
          } else {
            this.reportArtifactList = data;
            column.dicData = data.map((item) => {
              item.label = item.materialName + '(' + item.materialNo + ')';
              item.value = item.id;
              return item;
            });
          }
        });
      }
    },
    'form.reportArtifacts'(val, oldVal) {
      if (val) {
        this.reportArtifactList.every((item) => {
          if (item.id == val) {
            this.$set(this.form, 'boxCounts', item.boxCounts);
            return false;
          } else {
            return true;
          }
        });
      }
    },
  },
  mounted() {},
  methods: {
    changeReportType(val, row, index) {
      if (val) {
        this.$set(this.infoData[index], 'reportArtifacts', '');
        getTypeProducts({ materialType: val }).then((res) => {
          const data = res.data.data;
          if (data.length == 0) {
            this.infoData[index].reportArtifactList.length = 0;
            column.dicData.length = 0;
          } else {
            let reportArtifactList = data.map((item) => {
              item.label = item.materialName + '(' + item.materialNo + ')';
              item.value = item.id;
              return item;
            });
            this.$set(this.infoData[index], 'reportArtifactList', reportArtifactList);
          }
        });
      }
    },
    changeReportPro(val, row, index) {
      if (val) {
        row.reportArtifactList.every((item) => {
          if (item.id == val) {
            this.$set(this.infoData[index], 'boxCounts', item.boxCounts);
            return false;
          } else {
            return true;
          }
        });
      }
    },
    validProcedureData(data) {
      let equipMsg = '';
      if (data.length > 0) {
        data.every((item, index) => {
          if (item.reportType == '') {
            equipMsg = `【工序清单】第${index + 1}行 请选择报工方式`;
            this.$message.error(equipMsg);
            return false;
          } else if (item.reportArtifactsType == '') {
            equipMsg = `【工序清单】第${index + 1}行 请选择报工件类别`;
            this.$message.error(equipMsg);
            return false;
          } else if (item.reportArtifacts == '') {
            equipMsg = `【工序清单】第${index + 1}行 请选择报工件产品`;
            this.$message.error(equipMsg);
            return false;
          } else if (item.boxCounts == '') {
            equipMsg = `【工序清单】第${index + 1}行 请输入标箱数量`;
            this.$message.error(equipMsg);
            return false;
          } else if (!numparZReg.test(item.boxCounts)) {
            equipMsg = `【工序清单】第${index + 1}行 标箱数量请输入整数（包含0）`;
            this.$message.error(equipMsg);
            return false;
          } else if (item.quota == '') {
            equipMsg = `【工序清单】第${index + 1}行 请输入定额`;
            this.$message.error(equipMsg);
            return false;
          } else if (!numparZReg.test(item.quota)) {
            equipMsg = `【工序清单】第${index + 1}行 定额请输入整数（包含0）`;
            this.$message.error(equipMsg);
            return false;
          } else {
            return true;
          }
        });
        if (equipMsg) {
          return false;
        }
      }
      return true;
    },
    handleAdd() {
      this.updateBatch = false;
      this.option.addTitle = '新增';
      this.$refs.crud.rowAdd();
    },
    updateBatchFun() {
      this.updateBatch = true;
      this.option.addTitle = '批量编辑';
      this.$refs.crud.rowAdd();
    },
    rowSave(row, done, loading) {
      if (this.infoData.length == 0) {
        this.$message.warning('请维护产品工序信息');
        loading();
        return;
      }
      let valid = this.validProcedureData(this.infoData);
      if (!valid) {
        loading();
        return;
      }
      let content = this.infoData.map((item) => {
        item.productId = this.productId;
        item.fileNo = row.fileNo;
        item.version = row.version;
        return item;
      });
      if (this.updateBatch) {
        uploadBatchFlow(content).then(
          () => {
            this.onLoad();
            this.$message({
              type: 'success',
              message: '操作成功!',
            });
            done();
          },
          (error) => {
            window.console.log(error);
            loading();
          }
        );
      } else {
        addFlow(content).then(
          () => {
            this.onLoad();
            this.$message({
              type: 'success',
              message: '操作成功!',
            });
            done();
          },
          (error) => {
            window.console.log(error);
            loading();
          }
        );
      }
    },
    changeProductSc(val, row, index) {
      if (val) {
        this.productScList.every((item) => {
          if (item.id == val) {
            this.$set(this.characterData[index], 'procedureSc', item.procedureSc);
            this.$set(this.characterData[index], 'scKind', item.scKind);
            return false;
          } else {
            return true;
          }
        });
      }
    },
    rowCharSave(row, done, loading) {
      this.characterData.push(row);
      done();
    },
    rowCharUpdate(row, index, done, loading) {
      this.characterData.splice(index, 1, row);
      done();
    },
    rowCharDel(row, index) {
      console.log(index);
      this.$confirm('确定将此数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.characterData.splice(index, 1);
      });
    },
    validCharacter(data) {
      let equipMsg = '';
      let productScSet = new Set();
      if (data.length > 0) {
        data.every((item, index) => {
          if (item.productSc == '') {
            equipMsg = `【产品特性清单】第${index + 1}行 请选择产品特性`;
            this.$message.error(equipMsg);
            return false;
          } else {
            return true;
          }
        });
        if (equipMsg) {
          return false;
        }
        data.forEach((item) => {
          productScSet.add(item.productSc);
        });
        if (productScSet.size < data.length) {
          equipMsg = `【产品特性清单】 有重复产品特性，请删除重复的信息`;
          this.$message.error(equipMsg);
        }
        if (equipMsg) {
          return false;
        }
      }
      return true;
    },
    rowUpdate(row, index, done, loading) {
      // if (this.characterData.length == 0) {
      //   this.$message.warning('请添加产品特性');
      //   loading();
      //   return;
      // }
      let valid = this.validCharacter(this.characterData);
      if (!valid) {
        loading();
        return;
      }
      row.scListIds = this.characterData
        .map((item) => {
          return item.productSc;
        })
        .join(',');
      updateFlow(row).then(
        () => {
          this.onLoad();
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          done();
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return removeFlow(row.id);
        })
        .then(() => {
          this.onLoad();
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return removeFlow(this.ids);
        })
        .then(() => {
          this.onLoad();
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          this.$refs.crud.toggleSelection();
        });
    },
    beforeOpen(done, type) {
      this.type = type;
      if (type == 'view') {
        this.characterOption.header = false;
        this.characterOption.menu = false;
      } else {
        this.characterOption.header = true;
        this.characterOption.menu = true;
      }
      if (['edit', 'view'].includes(type)) {
        getFlow(this.form.id).then((res) => {
          let data = res.data.data;
          // delete data.procedureName;
          this.form = data;
          this.characterData = data.prdScLists;
        });
      } else {
        if (this.updateBatch) {
          this.infoloading = true;
          this.$set(this.form, 'materialName', this.materialName);
          this.$set(this.form, 'innerDrawingNo', this.innerDrawingNo);
          this.$set(this.form, 'materialNo', this.materialNo);
          this.$set(this.form, 'reportType', '1');
          let typeList = ['PB', 'PZ', 'PW', 'PC'];
          let proList = [];
          for (let i = 0; i < 4; i++) {
            proList[i] = new Promise(function (resolve, reject) {
              let list = [];
              getTypeProducts({ materialType: typeList[i] }).then((res) => {
                const data = res.data.data;
                if (data.length == 0) {
                  list.length = 0;
                  list = [];
                } else {
                  list = data.map((item) => {
                    item.label = item.materialName + '(' + item.materialNo + ')';
                    item.value = item.id;
                    return item;
                  });
                }
                resolve(list);
              });
            });
          }
          // 同时执行...proList，并在它们都完成后执行then:
          Promise.all(proList).then((results) => {
            getFlowList({ productId: this.productId }).then((res) => {
              const data = res.data.data;
              this.infoData = data.map((item) => {
                item.combinationProcedureNo = item.stepNo;
                if (item.reportArtifactsType) {
                  if (item.reportArtifactsType == 'PB') {
                    item.reportArtifactList = results[0];
                  } else if (item.reportArtifactsType == 'PZ') {
                    item.reportArtifactList = results[1];
                  } else if (item.reportArtifactsType == 'PW') {
                    item.reportArtifactList = results[2];
                  } else if (item.reportArtifactsType == 'PC') {
                    item.reportArtifactList = results[3];
                  }
                } else {
                  item.reportArtifactList = [];
                }
                item.$cellEdit = true;
                return item;
              });
              this.$set(this.form, 'fileNo', data[0].fileNo);
              this.$set(this.form, 'version', data[0].version);
              this.infoloading = false;
            });
          });
        } else {
          this.infoloading = true;
          getProProcessList({ productId: this.productId }).then((res) => {
            const data = res.data.data;
            this.infoData = data.map((item) => {
              return {
                procedureId: item.id,
                combinationProcedureNo: item.combinationProcedureNo,
                procedureName: item.procedureName,
                reportType: '1',
                reportArtifactsType: '',
                reportArtifacts: '',
                boxCounts: '',
                quota: '',
                $cellEdit: true,
              };
            });
            this.infoloading = false;
          });
          Object.keys(this.form).forEach((key) => (this.form[key] = ''));
          this.$set(this.form, 'materialName', this.materialName);
          this.$set(this.form, 'innerDrawingNo', this.innerDrawingNo);
          this.$set(this.form, 'materialNo', this.materialNo);
          this.$set(this.form, 'reportType', '1');
        }
      }
      done();
    },
    updateTable() {
      this.onLoad();
    },
    getColumns() {
      getTemplate({ executeType: '3' }).then((res) => {
        let data = res.data.data;
        if (JSON.stringify(data) == '{}') {
          this.checkList.length = 0;
          this.checkList = [];
          this.columnList.forEach((item) => {
            if (item.defaultChecked) {
              this.checkList.push(item.prop);
            }
          });
          this.notEmpty = false;
        } else {
          this.notEmpty = true;
          this.checkList = data.columnList;
          this.checkList.forEach((item) => {
            this.option.column.every((col, index) => {
              if (col.prop == item) {
                this.option.column[index].hide = false;
                return false;
              } else {
                return true;
              }
            });
          });
        }
      });
    },
    onLoad(page, params = {}) {
      this.loading = true;
      if (!this.productId) {
        return false;
      }
      this.query.productId = this.productId;
      getFlowList(Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.data = data;
        if (data.length > 0) {
          this.created = true;
        } else {
          this.created = false;
        }
        this.loading = false;
        this.selectionClear();
      });

      getProdProcess(this.productId).then((res) => {
        this.procedureList = res.data.data;
      });
      // 报工件类别下拉列表
      getBusinessList('reportArtifactsType').then((res) => {
        this.reportTypeList = res.data.data;
      });
      // 根据产品id获取产品特性下拉选
      getProdFeatures(this.productId).then((res) => {
        this.productScList = res.data.data;
      });
      getQualityList().then((res) => {
        this.findObject(this.characterOption.column, 'scKind').dicData = res.data.data;
      });
    },
  },
};
</script>

<style lang="scss">
.avue--view {
  .el-input-group--append {
    width: 120px;
    .el-input__inner {
      padding-right: 0;
    }
    .el-input-group__append {
      padding: 0;
    }
  }
}
</style>